package top.fyukina.fymil;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class DataType<T> implements RegName<String> {
    private final String name;
    private final T defaultVal;
    private static final Map<String, DataType<?>> dataTypes = new HashMap<>();
    private DataType(String name, T defaultVal) {
        this.name = name;
        this.defaultVal = defaultVal;
    }
    public static DataType<?> type(String regName) {
        DataType<?> type = dataTypes.get(regName);
        return type == null ? STRING : type;
    }
    public static Object getDefaultNonType() {
        return "";
    }
    public T getDefault() {
        return defaultVal;
    }
    @Override
    public String toString() {
        return name;
    }
    public static final DataType<BigDecimal> NUMBER = new DataType<>("number", BigDecimal.ZERO);
    public static final DataType<Boolean> BOOLEAN = new DataType<>("boolean", true);
    public static final DataType<String> STRING = new DataType<>("string", "");
    static {
        dataTypes.put(NUMBER.registerName(), NUMBER);
        dataTypes.put(BOOLEAN.registerName(), BOOLEAN);
        dataTypes.put(STRING.registerName(), STRING);
    }
    @Override
    public String registerName() {
        return name;
    }
}